/**
 * Copyright &copy; 2012-2016 civet All rights reserved.
 */
package cn.mcsys.myadmin.modules.air.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.mcsys.myadmin.common.config.Global;
import cn.mcsys.myadmin.common.persistence.Page;
import cn.mcsys.myadmin.common.web.BaseController;
import cn.mcsys.myadmin.common.utils.StringUtils;
import cn.mcsys.myadmin.modules.air.entity.AirClient;
import cn.mcsys.myadmin.modules.air.service.AirClientService;

/**
 * 客户管理Controller
 * @author leopold
 * @version 2018-08-13
 */
@Controller
@RequestMapping(value = "${adminPath}/air/airClient")
public class AirClientController extends BaseController {

	@Autowired
	private AirClientService airClientService;
	
	@RequiresPermissions("air:airClient:view")
	@RequestMapping(value = {"list", ""})
	public String list(AirClient airClient, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AirClient> page = airClientService.findPage(new Page<AirClient>(request, response), airClient); 
		model.addAttribute("page", page);
		return "modules/air/airClientList";
	}

	@RequiresPermissions("air:airClient:view")
	@RequestMapping(value = "form")
	public String form(AirClient airClient, Model model) {
	    if (airClient.getId() != null){
            airClient = airClientService.get(airClient.getId());
        }
		model.addAttribute("airClient", airClient);
		return "modules/air/airClientForm";
	}

	@RequiresPermissions("air:airClient:edit")
	@RequestMapping(value = "save")
	public String save(AirClient airClient, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, airClient)){
			return form(airClient, model);
		}
		airClientService.save(airClient);
		addMessage(redirectAttributes, "保存客户成功");
		return "redirect:"+Global.getAdminPath()+"/air/airClient/?repage";
	}
	
	@RequiresPermissions("air:airClient:edit")
	@RequestMapping(value = "delete")
	public String delete(AirClient airClient, RedirectAttributes redirectAttributes) {
		airClientService.delete(airClient);
		addMessage(redirectAttributes, "删除客户成功");
		return "redirect:"+Global.getAdminPath()+"/air/airClient/?repage";
	}

}